package com.LachesismStorm.lachesism.member.service.ofaServiceUtil;

import com.LachesismStorm.lachesism.core.service.RedisService;
import com.LachesismStorm.lachesism.core.util.LachesismTools;
import com.LachesismStorm.lachesism.member.mapper.OfficalAccountMapper;
import com.LachesismStorm.lachesism.member.service.impl.OfficalAccountServiceImpl;
import com.LachesismStorm.lachesism.member.vo.UmsMember;
import com.LachesismStorm.lachesism.member.vo.ofaVO.MessageTextInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @Author lachesism
 * @Date 2025-06-02 23:55
 **/
@Service
public class recordDietImpl implements recordDiet{

    @Resource
    private RedisService redisService;

    @Resource
    private OfficalAccountServiceImpl ofaService;
    @Resource
    private OfficalAccountMapper officalAccountMapper;

    @Override
    public String recordDiet(MessageTextInfo messageTextInfo) throws Exception {
        String openId = messageTextInfo.getFromUserName();
        if (ofaService.checkIsNewUser(openId)) {
            redisService.set(openId, "饮食");
            SortedMap<String, String> req = new TreeMap<String, String>();
            req.put("FromUserName", messageTextInfo.getToUserName());
            req.put("ToUserName", openId);
            req.put("CreateTime", String.valueOf(messageTextInfo.getCreateTime().getTime()));
            req.put("MsgType", "text");
            req.put("Content", "好的，切换到记录饮食，后续输入任何内容直接记录当作食物记录");
            return LachesismTools.convertMapToXml(req);
        } else {
            redisService.set(openId, "新用户饮食");
            SortedMap<String, String> req = new TreeMap<String, String>();
            req.put("FromUserName", messageTextInfo.getToUserName());
            req.put("ToUserName", openId);
            req.put("CreateTime", String.valueOf(messageTextInfo.getCreateTime().getTime()));
            req.put("MsgType", "text");
            req.put("Content", "好的，切换到记录饮食，后续输入任何内容直接记录当作食物记录");
            return LachesismTools.convertMapToXml(req);
        }
    }

    @Override
    public String continueRecordDiet(MessageTextInfo messageTextInfo) {
        return null;
    }

}
